package com.xjz.config;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.region.Region;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ClassName: CosClientConfig
 * Package: com.xjz.config
 * Description:
 *  腾讯云对象存储服务
 * @Author 许小健
 * @Create 2025/8/2 10:23
 * @Version 1.0
 */

@Configuration
@ConfigurationProperties(prefix = "cos.client")
@Data
public class CosClientConfig {

    private String region;

    private String bucket;

    private String secretId;

    private String secretKey;

    @Bean
    public COSClient cosClient() {
        //初始化用户身份信息(secretId, secretKey)
        BasicCOSCredentials cred = new BasicCOSCredentials(secretId, secretKey);

        //设置bucket的区域, COS地域的简称请参见 https://cloud.tencent.com/document/product/436/6224
        ClientConfig clientConfig = new ClientConfig(new Region(region));

        //生成cos客户端
        return new COSClient(cred, clientConfig);
    }
}
